package com.app.micaihu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Space;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.news.NewsEntity;
import com.app.micaihu.bean.news.VideoRankEntity;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.image.LoadImageUtils;
import com.baidu.mobstat.StatService;

import java.util.List;

/**
 * Created by Guo on 2017/7/3.
 *
 * 在排行榜中的热点
 *
 */

public class HotNewsRankAdapter extends AppBaseAdapter<NewsEntity> {
    public HotNewsRankAdapter(List<NewsEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_video_rank,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        StatService.onEvent(context, "article_exposed", "内容榜_文章", 1);// 统计的点击的次数
        NewsEntity newsEntity = list.get(position);
        if(newsEntity == null){
            return convertView;
        }

        viewHolder.tvTitle.setText(newsEntity.getArticleTitle());
        viewHolder.tvDesc.setText(newsEntity.getArticleTime());
        if(newsEntity.getArticleThumb() != null && newsEntity.getArticleThumb().length > 0){
            LoadImageUtils.getInstance().loadImage(viewHolder.icvThumb,newsEntity.getArticleThumb()[0]);

        }
        viewHolder.tvCount.setText(newsEntity.getCommentNum()+"评论");

        viewHolder.numTv.setVisibility(View.INVISIBLE);
        viewHolder.numIcon.setVisibility(View.VISIBLE);
        viewHolder.rankNum.setVisibility(View.GONE);
        viewHolder.space.setVisibility(View.VISIBLE);
        return convertView;
    }


    class ViewHolder{
        private TextView tvTitle;
        private TextView tvDesc;
        private TextView tvCount;
        private CustomImageView icvThumb;

        private ImageView numIcon;
        private TextView numTv;

        private FrameLayout rankNum;
        private Space space;
        public ViewHolder(View contentView){
            tvTitle = (TextView)contentView.findViewById(R.id.video_title);
            tvDesc = (TextView)contentView.findViewById(R.id.video_time);
            tvCount = (TextView)contentView.findViewById(R.id.video_count);
            numTv = (TextView)contentView.findViewById(R.id.tv_rank_num);
            numIcon = (ImageView) contentView.findViewById(R.id.iv_rank_num);
            icvThumb = (CustomImageView) contentView.findViewById(R.id.video_logo);
            rankNum = (FrameLayout) contentView.findViewById(R.id.rank_num);
            space = (Space) contentView.findViewById(R.id.space);

        }

    }
}
